package com.atguigu.servlet;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/servlet6")
public class servlet6 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置响应行相关的api
        resp.setStatus(405);
        //设置响应头相关的api
     /*   resp.setHeader("Content-Type","aaa");*/
       /* resp.setContentLength(1234);*/
        String info = "<h1>hello</h1>";
        resp.setContentType("text/html");
        resp.setContentLength(info.getBytes().length);
        //设置响应体内容
        //获得一个响应体中输入文本的字符输入流
        PrintWriter writer = resp.getWriter();
        writer.write(info);
    }
}
